<template>
  <div>
    <!-- 折扣政策设置 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTables
      ref="table"
      columnsRef="qjhRebateRulesSet"
      :columns="columns"
      :isSelectColumn="false"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <!-- <template slot="controls">
        <el-button size="small" type="primary" @click="addHandle">新 增</el-button>
      </template> -->
       <template slot="controls" slot-scope="props">
        <!-- <el-button size="small" type="primary" icon="el-icon-download" @click="downloadHandle">下载模板</el-button>
        <multiuse-button size="small" type="primary" @click="ImportExcel">数据导入</multiuse-button> -->
        <multiuse-button size="small" type="primary" @click="importHandler">导入</multiuse-button>
       </template>
    </FilterTables>

    <BaseDialog :visible.sync="visible" :title="drawerTitle" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SonModel :type="handleType" :rowData="formData" @close="emitCloseHandler" />
    </BaseDialog>
 <!-- 导入 -->
    <BaseDialog :visible.sync="isImport" title="数据导入" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ImportFile :rowData="formData" @close="emitCloseHandler2" />
    </BaseDialog>


  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList,downAssemblyTem,ImportExcel } from '@/api/omSaleP/vehicleParameters/RebateManage/RebateRulesSet';
import SonModel from './SonModel';
import ImportFile from './ImportFile';

export default {
  name: 'RebateRulesSet',
  mixins: [dictionary],

  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '详情' };
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {
        // optionCode: '',
        // optionName: '',
        // powerType: '',
        // rebateType: '',
        // status: '',
        // startDate: '',
        // endDate: ''
      },
      formData: {},
      visible: false,
      handleType: '',
      drawerTitle: '',
      ImportExcel: false,
       isImport: false,

    };
  },
  components: {
    SonModel,
    ImportFile
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
downloadHandle() {
      this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        confirmButtonText: '下载',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          downAssemblyTem()
            .then(res => {
        
              exportExcelFile(res.data, '折扣政策设置');
            })
            .catch(err => {});
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
},
       importHandler() {
      this.isImport = true;
    },
    emitCloseHandler2(val, type) {
      this.isImport = val;
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    selectChangeHandle(row) {},
    seacherFun() {
      this.issearch = true;
    },
    addHandle() {
      this.handleType = 'add';
      this.formData = {};
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit';
      this.formData = row;
     
      this.showHandler();
    },
    showHandler() {
      this.drawerTitle = `${this.conf[this.handleType]}`;
      this.visible = true;
    },
    emitCloseHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '物料编码',
          fieldName: 'productCode',
          placeholder: '请输入',
        },
        {
          type: 'INPUT',
          label: '物料描述',
          fieldName: 'productName',
          placeholder: '请选择'
        },
        // {
        //   type: 'SELECT',
        //   label: '启用状态',
        //   fieldName: 'status',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('1003')
        // },
        {
          type: 'RANGE_DATE',
          label: '有效开始日期：',
          fieldName: 'startDate|endDate',
          dateType: 'exactdaterange',
          placeholder: '请选择',
          initialValue: []
        },
   
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   fixed: 'left',
        //   render: (props, h) => {
        //     return (
        //       <div>
        //         <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
        //           编辑
        //         </multiuse-button>
        //       </div>
        //     );
        //   }
        // },

        // {
        //   title: '状态',
        //   dataIndex: 'status',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1003'),
        //   render: p => {
        //     return <span>{this.createDictText(p.row.status, '1003')}</span>;
        //   }
        // },


        {
          title: '现金折让',
          dataIndex: 'discountPrice',
          sorter: true,
          filter: true,
          filterType: 'input',
                    align: 'right',
          precision: 2,
          numberFormat: true
        },
          {
          title: '有效开始日期',
          dataIndex: 'startDate',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '有效结束日期',
          dataIndex: 'endDate',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
                {
          title: '物料编码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          align: 'center',
          width: 200,
          filterType: 'input'
        },
        {
          title: '物料描述',
          dataIndex: 'productName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'brandName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '配置',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '选装',
          dataIndex: 'optionName',
          align: 'center',
          width: 250,
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '内饰',
          dataIndex: 'trimName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '外饰',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
                  {
          title: '创建人',
          dataIndex: 'createdName',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '创建时间',
          dataIndex: 'createdAt',
          align: 'center',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '更新人',
          dataIndex: 'updatedName',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '更新时间',
          dataIndex: 'updatedAt',
          align: 'center',
          width: 200,
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      
      ];
    }
  }
};
</script>
